<script type="text/javascript">
	var url = "{BEESCRM::C('site_url').U('Coupon/coupon/index',array('data'=>base64_encode(json_encode(array('act_id' => $coupon['act_id'],'account_id' => $coupon['account_id'])))))}";
	var imgUrl = "{BEESCRM:$coupon.img}";
	var title = "送你一张【{BEESCRM:$coupon.title}】,快来领吧！";
	var desc = "{BEESCRM:$coupon.title}";
	wx.config({
		debug: false,
		appId: "{BEESCRM:$appid}",
		timestamp: "{BEESCRM:$timestamp}",
		nonceStr: "{BEESCRM:$noncestr}",
		signature: "{BEESCRM:$signature}",
		jsApiList: ['checkJsApi','onMenuShareTimeline','onMenuShareAppMessage','hideOptionMenu','scanQRCode','openLocation','getLocation'],
	});
	
	wx.ready(function(){
		doShare(0);
	});

	function doShare(stype){
		//分享到朋友圈
		wx.onMenuShareTimeline({
			title: title, // 分享标题
			 link: url, // 分享链接
			imgUrl: imgUrl, // 分享图标 
			success: function () { 
				share(stype); 
			},
			cancel: function () { 
				// 用户取消分享后执行的回调函数
				 cancelShare();
			}
		});
		//发送给好友
		wx.onMenuShareAppMessage({
			title: title, // 分享标题
			desc: desc, // 分享描述
			link: url, // 分享链接
			imgUrl: imgUrl, // 分享图标
			type: '', // 分享类型,music、video或link，不填默认为link
			dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
			success: function () { 
				// 用户确认分享后执行的回调函数
				share(stype);
			},
			cancel: function () { 
				// 用户取消分享后执行的回调函数
				cancelShare();
			}
		});
	}
	
	function share(types){
		var jumpUrl = location.href;
		if(types == 1){
			$.ajax({
				url:"{BEESCRM::U('coupon/coupon/sendToUser',array('account_id'=>$coupon['account_id'],'record_id'=>$record_info['record_id']))}",
				type:"post",
				dataType:"json",
				success:function(data){
					if(data.status == 'S'){
						
						location.href = jumpUrl;
					}else{
						$.alert('error',data.message);
					}
				}
			})
		}else{
			location.href = jumpUrl;
		}
	}

	function cancelShare(){
		/*url = "{BEESCRM::C('site_url').U('Coupon/coupon/index',array('data'=>base64_encode(json_encode(array('act_id' => $coupon['act_id'],'account_id' => $coupon['account_id'])))))}";
		wx.ready(function(){
				doShare();
		});*/
	}
</script>
	